package open.witype.filetiper.activity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;


import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;

import open.witype.filetiper.R;
import open.witype.filetiper.custom.Slidingmenu.SlidingMenuView;
import open.witype.filetiper.fragment.menu.db.FavoDBAdapter;
import open.witype.filetiper.service.FileScanService;

/**
 * Created by Typer on 2015/5/10 0010.
 *
 */
public class BaseActivity extends AppCompatActivity {

    private SlidingMenuView mSlidingRecyclerView;

    private FileScanService.ServiceBinder mService;

    private boolean mBound;

    private FavoDBAdapter favoDBAdapter;

    public Toolbar toolbar;

    public Toolbar bottomToolbar;

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        initToolbar();
    }

    public void initToolbar(){
        toolbar = (Toolbar)findViewById(R.id.toolbar);
        bottomToolbar = (Toolbar)findViewById(R.id.toolbar_bottom);
        bottomToolbar.inflateMenu(R.menu.menu_normal);
        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        toolbar.setLogo(R.mipmap.ic_launcher);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_home, menu);
        return true;
    }

    public void initService(){
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(),FileScanService.class);
        bindService(intent, conn,Context.BIND_AUTO_CREATE);
    }

    private ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            FileScanService.ServiceBinder serviceBinder = (FileScanService.ServiceBinder)service;
            mService = serviceBinder.getService();
            mBound = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mBound = false;
            mService = null;
        }
    };

    public void show(String text) {
        Snackbar snackbar = Snackbar.with(this).text(text);
        SnackbarManager.show(snackbar);
    }
}
